package com.zhiwei.msf.infra.oauth.controller;

import com.zhiwei.msf.infra.oauth.constants.ResponseMsg;
import com.zhiwei.msf.infra.oauth.entity.UserInfo;
import com.zhiwei.msf.infra.oauth.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * function 用户控制器
 * author zhiwei.yang
 * time 2020-2-25-14:57
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserInfoService userInfoService;

    /**
     * 增加用户
     * @return
     */
    @PostMapping("/add")
    public ResponseMsg addUser(@RequestBody UserInfo userInfo){
        if(userInfoService.addUser(userInfo)){
            return ResponseMsg.buildSuccessResponseMsg(null);
        }
        return ResponseMsg.buildFailResponseMsg(null);
    }

    /**
     * 删除用户
     * @return
     */
    @GetMapping("/delete")
    public ResponseMsg deleteUser(String userId){
        if(userInfoService.deleteUser(userId)){
            return ResponseMsg.buildSuccessResponseMsg(null);
        }
        return ResponseMsg.buildFailResponseMsg(null);
    }

    /**
     * 更新用户
     * @return
     */
    @GetMapping("/update")
    public ResponseMsg updateUser(@RequestBody UserInfo userInfo){
        if(userInfoService.updateUser(userInfo)){
            return ResponseMsg.buildSuccessResponseMsg(null);
        }
        return ResponseMsg.buildFailResponseMsg(null);
    }

    /**
     * 查询用户
     * @return
     */
    @GetMapping("/query")
    public ResponseMsg queryUser(String userId){
        return ResponseMsg.buildFailResponseMsg(userInfoService.queryUser(userId));
    }
}